package com.xiaoqi.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaoqi.dao.RoleDao;
import com.xiaoqi.pojo.PageResult;
import com.xiaoqi.pojo.QueryPageBean;
import com.xiaoqi.pojo.Role;
import com.xiaoqi.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author PC
 * creationTime: 2022/11/6 18:04
 */

@Service(interfaceClass = RoleService.class)
@Transactional
public class RoleServiceimpl implements RoleService {

    @Autowired
    private RoleDao roleDao;

    /**
     * 查询所有角色
     * @return
     */
    @Override
    public PageResult findAll(QueryPageBean queryPageBean) {
        //分页插件开启分页
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //开启后的第一条查询语句会被分页
        List<Role> list = roleDao.findAll(queryPageBean.getQueryString());
        //完善分页查询信息
        PageInfo<Role> pageInfo = new PageInfo<>(list);
        return new PageResult(pageInfo.getTotal(),pageInfo.getList());
    }
}
